package student.controller;

import student.domain.Student;
import student.service.StuSer;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author 嘉德罗斯
 * @date 2021/7/19
 */
public class StuCon {
    Scanner sc = new Scanner(System.in);
    StuSer ser = new StuSer();
    public void enter(){
        String name = "嘉德罗斯";
        String password= "951473";
        while (true){
            System.out.println("请输入用户名");
            String name1 =sc.next();
            System.out.println("请输入密码");
            String password1 = sc.next();
            if(name.equals(name1) && password.equals(password1)){
                show();
            }else {
                System.out.println("用户名或密码错误");
                System.out.println("请重新输入");
            }
        }
    }
    public void show() {
        while (true) {
            System.out.println("欢迎进入管理系统");
            System.out.println("1，学生管理 2， 老师管理 3，退出");
            System.out.println("请输入你的选择：");
            int a = sc.nextInt();
            switch (a) {
                case 1:
                    show2();
                    break;
                case 2:
                    System.out.println("老师管理");
                    break;
                case 3:
                    System.out.println("退出");
                    return;
                default:
                    System.out.println("目前没有这个功能，请重新输入");
                    break;
            }
        }
    }
    public void show2(){
        while (true){
        System.out.println("1，添加 2，删除 3，修改 4，查看 5，退出");
        System.out.println("请输入");
        int a = sc.nextInt();
        switch (a) {
            case 1:
                add();
                break;
                case 2:
                    if(ser.sky()){
                    break;
                    }
                    System.out.println("请输入你要删除的id");
                    String id = sc.next();
                    if (delete(id)){
                        System.out.println("删除成功");
                    }else{
                        System.out.println("id不存在");
                        System.out.println("删除失败");
                    }
                break;
                case 3:
                if(ser.sky()){
                    break;
                }
                    System.out.println("请输入你要修改的id");
                    String idx = sc.next();
                if (amend(idx)){
                    System.out.println("修改成功");
                }else{
                    System.out.println("id不存在");
                    System.out.println("修改失败");
                }
                break;
                case 4:
                    if (ser.sky()){
                        break;
                    }
                look();
                break;
                case 5:
                System.out.println("退出");
                return;
                default:
                System.out.println("目前没有此功能");
            }
        }
    }
    public void add(){
        System.out.println("请输入学生id");
        String id = sc.next();
        Student stu = new Student();
        stu.setId(id);
        if (ser.traverse(id)){
            System.out.println("请输入学生名字");
            String name = sc.next();
            stu.setName(name);
            System.out.println("请输入学生年龄");
            String age = sc.next();
            stu.setAge(age);
            System.out.println("请输入学生生日");
            String birthing =sc.next();
            stu.setBirthday(birthing);
            ser.add(stu);
        }else {
            System.out.println("你输入的id已存在");
            System.out.println("请重新输入");
        }
    }
    public  void look(){
        ser.look();
    }
    public boolean delete(String id){
        return ser.delete(id);
    }
    public boolean amend(String idx){
        return ser.amend(idx);
    }
}
